package com.gnerv.battle.boot.project.guard.service.impl;

import com.gnerv.battle.boot.project.guard.mapper.MonitorProjectNodeMapper;
import com.gnerv.battle.boot.project.guard.model.bo.MonitorProjectNodeBO;
import com.gnerv.battle.boot.project.guard.model.dto.MonitorProjectNodeDTO;
import com.gnerv.battle.boot.project.guard.model.entity.MonitorProjectNode;
import com.gnerv.battle.boot.project.guard.service.MonitorProjectNodeService;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.gnerv.battle.boot.common.tools.PageTools.limitSize;
import static com.gnerv.battle.boot.common.tools.PageTools.limitStart;

/**
 * @author Gnerv LiGen
 */
@Slf4j
@Service
@AllArgsConstructor
public class MonitorProjectNodeServiceImpl implements MonitorProjectNodeService {
    
    private final MonitorProjectNodeMapper monitorProjectNodeMapper;

    @Override
    public boolean create(@NonNull MonitorProjectNodeBO monitorProjectNodeBO) {
        MonitorProjectNode monitorProjectNode = monitorProjectNodeBO.toCreateMonitorProjectNode();
        monitorProjectNodeMapper.insert(monitorProjectNode);
        return true;
    }

    @Override
    public boolean deleteByUkId(@NonNull String ukId) {
        monitorProjectNodeMapper.deleteByUkId(ukId);
        return true;
    }

    @Override
    public boolean updateByUkId(@NonNull MonitorProjectNodeBO monitorProjectNodeBO) {
        MonitorProjectNode monitorProjectNode = monitorProjectNodeBO.toUpdateMonitorProjectNode();
        monitorProjectNodeMapper.updateByUkId(monitorProjectNode);
        return true;
    }

    @Override
    public MonitorProjectNodeDTO selectByUkId(@NonNull String ukId) {
        return monitorProjectNodeMapper.selectByUkId(ukId);
    }

    @Override
    public List<MonitorProjectNodeDTO> listByName(String name, Integer page, Integer size) {
        return monitorProjectNodeMapper.listByName(name, limitStart(page, size), limitSize(size));
    }

    @Override
    public String selectConfigFileByUkId(String ukId) {
        return monitorProjectNodeMapper.selectConfigFileByUkId(ukId);
    }

    @Override
    public String selectHostByUkId(String ukId) {
        return monitorProjectNodeMapper.selectHostByUkId(ukId);
    }

}
